import { isNonempty } from './validate'

/**
 * 表单效验规则，必填
 * @param {string} message - 错误提示
 * @param {boolean} showSymbol - 是否显示必填符号 *
 */
export const ruleRequired = (message, showSymbol = true) => {
  const rules = []

  showSymbol && rules.push({ required: true, message })

  rules.push({
    validator (_, value, cb) {
      isNonempty(value) ? cb() : cb(new Error(message))
    }
  })

  return rules
}
